package org.wu.framework.authorization.platform.infrastructure.persistence;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Repository;
import org.wu.framework.authorization.platform.domain.model.sys.zone.application.version.SysZoneApplicationVersion;
import org.wu.framework.authorization.platform.domain.model.sys.zone.application.version.SysZoneApplicationVersionRepository;
import org.wu.framework.authorization.platform.infrastructure.converter.SysZoneApplicationVersionConverter;
import org.wu.framework.authorization.platform.infrastructure.entity.SysZoneApplicationVersionDO;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;

import java.util.List;
import java.util.stream.Collectors;
/**
 * describe 应用版本 
 *
 * @author Jia wei Wu
 * @date 2024/04/02 06:21 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence 
 **/
@Repository
public class SysZoneApplicationVersionRepositoryImpl implements SysZoneApplicationVersionRepository {

    @Resource
    LazyLambdaStream lazyLambdaStream;

    /**
     * describe 新增应用版本
     *
     * @param sysZoneApplicationVersion 新增应用版本
     * @return {@link Result< SysZoneApplicationVersion >} 应用版本新增后领域对象
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<SysZoneApplicationVersion> story(SysZoneApplicationVersion sysZoneApplicationVersion) {
        SysZoneApplicationVersionDO sysZoneApplicationVersionDO = SysZoneApplicationVersionConverter.INSTANCE.fromLazyZoneApplicationVersion(sysZoneApplicationVersion);
        lazyLambdaStream.upsert(sysZoneApplicationVersionDO);
        return ResultFactory.successOf();
    }

    /**
     * describe 批量新增应用版本
     *
     * @param sysZoneApplicationVersionList 批量新增应用版本
     * @return {@link Result<List< SysZoneApplicationVersion >>} 应用版本新增后领域对象集合
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<List<SysZoneApplicationVersion>> batchStory(List<SysZoneApplicationVersion> sysZoneApplicationVersionList) {
        List<SysZoneApplicationVersionDO> sysZoneApplicationVersionDOList = sysZoneApplicationVersionList.stream().map(SysZoneApplicationVersionConverter.INSTANCE::fromLazyZoneApplicationVersion).collect(Collectors.toList());
        lazyLambdaStream.upsert(sysZoneApplicationVersionDOList);
        return ResultFactory.successOf();
    }

    /**
     * describe 查询单个应用版本
     *
     * @param sysZoneApplicationVersion 查询单个应用版本
     * @return {@link Result< SysZoneApplicationVersion >} 应用版本领域对象
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<SysZoneApplicationVersion> findOne(SysZoneApplicationVersion sysZoneApplicationVersion) {
        SysZoneApplicationVersionDO sysZoneApplicationVersionDO = SysZoneApplicationVersionConverter.INSTANCE.fromLazyZoneApplicationVersion(sysZoneApplicationVersion);
        SysZoneApplicationVersion sysZoneApplicationVersionOne = lazyLambdaStream.selectOne(LazyWrappers.lambdaWrapperBean(sysZoneApplicationVersionDO), SysZoneApplicationVersion.class);
        return ResultFactory.successOf(sysZoneApplicationVersionOne);
    }

    /**
     * describe 查询多个应用版本
     *
     * @param sysZoneApplicationVersion 查询多个应用版本
     * @return {@link Result<List< SysZoneApplicationVersion >>} 应用版本领域对象
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<List<SysZoneApplicationVersion>> findList(SysZoneApplicationVersion sysZoneApplicationVersion) {
        SysZoneApplicationVersionDO sysZoneApplicationVersionDO = SysZoneApplicationVersionConverter.INSTANCE.fromLazyZoneApplicationVersion(sysZoneApplicationVersion);
        List<SysZoneApplicationVersion> sysZoneApplicationVersionList = lazyLambdaStream.selectList(LazyWrappers.lambdaWrapperBean(sysZoneApplicationVersionDO), SysZoneApplicationVersion.class);
        return ResultFactory.successOf(sysZoneApplicationVersionList);
    }

    /**
     * describe 分页查询多个应用版本
     *
     * @param size 当前页数
     * @param current 当前页
     * @param sysZoneApplicationVersion 分页查询多个应用版本
     * @return {@link Result<LazyPage< SysZoneApplicationVersion >>} 分页应用版本领域对象
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<LazyPage<SysZoneApplicationVersion>> findPage(int size, int current, SysZoneApplicationVersion sysZoneApplicationVersion) {
        SysZoneApplicationVersionDO sysZoneApplicationVersionDO = SysZoneApplicationVersionConverter.INSTANCE.fromLazyZoneApplicationVersion(sysZoneApplicationVersion);
        LazyPage<SysZoneApplicationVersion> lazyPage = new LazyPage<>(current,size);
        LazyPage<SysZoneApplicationVersion> lazyZoneApplicationVersionLazyPage = lazyLambdaStream.selectPage(LazyWrappers.lambdaWrapperBean(sysZoneApplicationVersionDO),lazyPage, SysZoneApplicationVersion.class);
        return ResultFactory.successOf(lazyZoneApplicationVersionLazyPage);
    }

    /**
     * describe 删除应用版本
     *
     * @param sysZoneApplicationVersion 删除应用版本
     * @return {@link Result< SysZoneApplicationVersion >} 应用版本
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<SysZoneApplicationVersion> remove(SysZoneApplicationVersion sysZoneApplicationVersion) {
        SysZoneApplicationVersionDO sysZoneApplicationVersionDO = SysZoneApplicationVersionConverter.INSTANCE.fromLazyZoneApplicationVersion(sysZoneApplicationVersion);
        //  lazyLambdaStream.delete(LazyWrappers.lambdaWrapperBean(sysZoneApplicationVersionDO));
        return ResultFactory.successOf();
    }

    /**
     * describe 是否存在应用版本
     *
     * @param sysZoneApplicationVersion 应用版本领域对象
     * @return {@link Result<Boolean>} 是否存在 true 存在，false 不存在     
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<Boolean> exists(SysZoneApplicationVersion sysZoneApplicationVersion) {
        SysZoneApplicationVersionDO sysZoneApplicationVersionDO = SysZoneApplicationVersionConverter.INSTANCE.fromLazyZoneApplicationVersion(sysZoneApplicationVersion);
        Boolean exists=lazyLambdaStream.exists(LazyWrappers.lambdaWrapperBean(sysZoneApplicationVersionDO));
        return ResultFactory.successOf(exists);
    }

}